//
//  SettingViewController.m
//  YiXiProject
//
//  Created by iMac on 2019/7/23.
//  Copyright © 2019 iMac. All rights reserved.
//

#import "SettingViewController.h"

#import "SetTopView.h"    // 头部导航视图
#import "SetImgView.h"    // img视图
#import "SetSlideCellTableViewCell.h"  // slide-cell

@interface SettingViewController () <SetTopBtnDelegate,UITableViewDelegate,UITableViewDataSource,SetBottomSlideDelegate,SetImageDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
{
    SetSlideCellTableViewCell *cell4;
    NSInteger imgBtnTag;
}

@property (nonatomic,strong) SetTopView *setTopV;   // 头部石头属性
@property (nonatomic,strong) SetImgView *setImgV;   // 头部imgView属性
@property (nonatomic,strong) UITableView *table;    // table
@property (nonatomic,strong) NSMutableArray *sectionArr,*cellArr,*textCellArr,*imgCurrentArr;  // 存放cell数据
@property (nonatomic,strong) NSString *minAgeInput;       // 最小年龄
@property (nonatomic,strong) NSString *maxAgeInput;       // 最大年龄
@property (nonatomic,strong) NSMutableArray *arrSaveImg;  // 点保存按钮时获取的图片路径
@property (nonatomic,strong) NSString *nameInput;         // 名字
@property (nonatomic,strong) NSString *jobInput;          // 工作
@property (nonatomic,strong) NSString *ageInput;          // 年龄
@property (nonatomic,strong) NSString *bioInput;          // 爱好
@property (nonatomic,strong) NSMutableArray *curArrSave;  // 要保存的图片数组
@property (nonatomic,assign) NSInteger numSave;
@property (nonatomic,strong) NSDictionary *dicList;

@property (nonatomic,assign) NSInteger isData;            // 保存条件

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //注册键盘弹出通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    
    //注册键盘隐藏通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
    _numSave = 0;
    _isData = 0;
    _nameInput = @"";
    _jobInput = @"";
    _ageInput = @"";
    _bioInput = @"";
    _minAgeInput = @"16";
    _maxAgeInput = @"22";
    
    _sectionArr = [[NSMutableArray alloc]initWithObjects:@"Name",@"Profession",@"Age",@"Bio",@"Seeking Age Range", nil];
    _cellArr = [[NSMutableArray alloc]initWithObjects:@"name",@"job",@"age",@"bio",@"Min",@"Max", nil];
    _imgCurrentArr = [[NSMutableArray alloc]initWithObjects:@"",@"",@"", nil];
    _textCellArr = [[NSMutableArray alloc]initWithObjects:@"",@"",@"",@"", nil];
    _arrSaveImg = [[NSMutableArray alloc]init];
    _curArrSave = [[NSMutableArray alloc]init];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mobileText:) name:UITextFieldTextDidChangeNotification object:nil];
    
    [self createTopView];
    
    [self.view addSubview:self.table];
    
    [self creatImgView];
    [self loadImgThree:5];
    
    [self reauestOneSelfDatas];
}

#pragma mark -- 获取数据
-(void)reauestOneSelfDatas
{
    kWeakSelf(self);
    
    [HttpDatas requestOneSelfDataHomeToken:@"f2e0c88f-7d32-3464-9cc5" success:^(id  _Nonnull json) {
        
        if([json isKindOfClass:[NSDictionary class]])
        {
            if([json[@"status"]integerValue] == 200)
            {
                weakself.dicList = json[@"data"];
                
                [weakself.curArrSave removeAllObjects];
                NSMutableArray *arrImgSave = [[NSMutableArray alloc]init];
                
                if (json[@"data"][@"photo"])
                {
                    [arrImgSave addObject:json[@"data"][@"photo"]];
                }
                
                if (json[@"data"][@"photo1"])
                {
                    [arrImgSave addObject:json[@"data"][@"photo1"]];
                    [weakself.imgCurrentArr replaceObjectAtIndex:0 withObject:json[@"data"][@"photo1"]];
                }
                
                if (json[@"data"][@"photo2"])
                {
                    [arrImgSave addObject:json[@"data"][@"photo2"]];
                    [weakself.imgCurrentArr replaceObjectAtIndex:1 withObject:json[@"data"][@"photo2"]];
                }
                
                if (json[@"data"][@"photo3"])
                {
                    [arrImgSave addObject:json[@"data"][@"photo3"]];
                    [weakself.imgCurrentArr replaceObjectAtIndex:2 withObject:json[@"data"][@"photo3"]];
                }
                
                if(arrImgSave.count > 0)
                {
                    [self firstLoadImgThree:arrImgSave];
                }
                
                weakself.curArrSave = arrImgSave;
                
                // 非空判断显示
                if(weakself.dicList[@"name"] == nil || [weakself.dicList[@"name"] isEqual:[NSNull null]])
                {
                    weakself.isData = 0;
                }
                else
                {
                    weakself.isData = 1;
                    weakself.nameInput = weakself.dicList[@"name"];
                    [weakself.textCellArr replaceObjectAtIndex:0 withObject:weakself.dicList[@"name"]];
                    [weakself.cellArr replaceObjectAtIndex:0 withObject:@""];
                }
                
                if(weakself.dicList[@"work"] == nil || [weakself.dicList[@"work"] isEqual:[NSNull null]])
                {
                    weakself.isData = 0;
                }
                else
                {
                    weakself.isData = 1;
                    weakself.jobInput = weakself.dicList[@"work"];
                    [weakself.textCellArr replaceObjectAtIndex:1 withObject:weakself.dicList[@"work"]];
                    [weakself.cellArr replaceObjectAtIndex:1 withObject:@""];
                }
                
                if(weakself.dicList[@"age"] == nil || [weakself.dicList[@"age"] isEqual:[NSNull null]])
                {
                    weakself.isData = 0;
                }
                else
                {
                    weakself.isData = 1;
                    weakself.ageInput = weakself.dicList[@"age"];
                    [weakself.textCellArr replaceObjectAtIndex:2 withObject:weakself.dicList[@"age"]];
                    [weakself.cellArr replaceObjectAtIndex:2 withObject:@""];
                }
                
                if(weakself.dicList[@"bio"] == nil || [weakself.dicList[@"bio"] isEqual:[NSNull null]])
                {
                    weakself.isData = 0;
                }
                else
                {
                    weakself.isData = 1;
                    weakself.bioInput = weakself.dicList[@"bio"];
                    [weakself.textCellArr replaceObjectAtIndex:3 withObject:weakself.dicList[@"bio"]];
                    [weakself.cellArr replaceObjectAtIndex:3 withObject:@""];
                }
                
                if(weakself.dicList[@"age_min"] == nil || [weakself.dicList[@"age_min"] isEqual:[NSNull null]])
                {
                    weakself.minAgeInput = @"16";
                }
                else
                {
                    weakself.minAgeInput = weakself.dicList[@"age_min"];
                }
                
                if(weakself.dicList[@"age_max"] == nil || [weakself.dicList[@"age_max"] isEqual:[NSNull null]])
                {
                    weakself.maxAgeInput = @"22";
                }
                else
                {
                    weakself.maxAgeInput = weakself.dicList[@"age_max"];
                }
                
                [weakself.table reloadData];
            }
            else
            {
                [SVProgressHUD showSuccessWithStatus:json[@"message"]];
                [SVProgressHUD dismissWithDelay:SVPROGRESSHUDTIME];
            }
        }
        
    } failure:^(NSError * _Nonnull err) {
        
    }];
}


#pragma smark -- 初始化导航视图
-(void)createTopView
{
    self.setTopV = [[SetTopView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, navCurentHeight+30)];
    self.setTopV.backgroundColor = WhiteColor;
    self.setTopV.delegate = self;
    [self.view addSubview:self.setTopV];
    
}

// 首次启动给图片赋值
-(void)firstLoadImgThree:(NSMutableArray *)photos
{
    if(photos.count == 1)
    {
        [self.setImgV.leftImg sd_setImageWithURL:[NSURL URLWithString:photos[0]] placeholderImage:nil];
    }
    else if (photos.count == 2)
    {
        [self.setImgV.leftImg sd_setImageWithURL:[NSURL URLWithString:photos[1]] placeholderImage:nil];
    }
    else if (photos.count == 3)
    {
        [self.setImgV.leftImg sd_setImageWithURL:[NSURL URLWithString:photos[1]] placeholderImage:nil];
        [self.setImgV.rightOneImg sd_setImageWithURL:[NSURL URLWithString:photos[2]] placeholderImage:nil];
    }
    else
    {
        [self.setImgV.leftImg sd_setImageWithURL:[NSURL URLWithString:photos[1]] placeholderImage:nil];
        [self.setImgV.rightOneImg sd_setImageWithURL:[NSURL URLWithString:photos[2]] placeholderImage:nil];
        [self.setImgV.rightTwoImg sd_setImageWithURL:[NSURL URLWithString:photos[3]] placeholderImage:nil];
    }
    
}

// 修改图片时执行这里更换图片显示
-(void)loadImgThree:(NSInteger)threeNum
{
    if(threeNum == 5)
    {
        
    }
    else
    {
        switch (threeNum) {
            case 100:
                [self imgData:_imgCurrentArr[0] Tag:threeNum];
                break;
                
            case 101:
                [self imgData:_imgCurrentArr[1] Tag:threeNum];
                break;
                
            case 102:
                [self imgData:_imgCurrentArr[2] Tag:threeNum];
                break;
                
            default:
                break;
        }
    }
}

-(void)imgData:(UIImage *)imgUrl Tag:(NSInteger)tag
{
    if(tag == 100)
    {
        //[self.setImgV.leftImg sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:nil];
        self.setImgV.leftImg.image = imgUrl;
    }
    else if(tag == 101)
    {
        //[self.setImgV.rightOneImg sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:nil];
        self.setImgV.rightOneImg.image = imgUrl;
    }
    else
    {
        //[self.setImgV.rightTwoImg sd_setImageWithURL:[NSURL URLWithString:imgUrl] placeholderImage:nil];
        self.setImgV.rightTwoImg.image = imgUrl;
    }

}

-(void)creatImgView
{
    _setImgV = [[SetImgView alloc]init];
    _setImgV.delegate = self;
    _setImgV.nameLabel.text = [NSString stringWithFormat:@"%@",_sectionArr[0]];
    [self.view addSubview:_setImgV];
    _setImgV.sd_layout.leftSpaceToView(self.view, 0).topSpaceToView(_setTopV, 0).rightSpaceToView(self.view, 0).heightIs(SCREEN_WIDTH);
}

-(UITableView *)table
{
    if(!_table)
    {
        _table = [[UITableView alloc]initWithFrame:CGRectMake(0, self.setTopV.bounds.size.height, SCREEN_WIDTH, SCREEN_HEIGHT-self.setTopV.bounds.size.height) style:UITableViewStyleGrouped];
        _table.delegate = self;
        _table.dataSource = self;
        _table.bounces = NO;
        _table.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _table;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _sectionArr.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return indexPath.section == _sectionArr.count-1 ? 150 : 50;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return section == 0 ? SCREEN_WIDTH : 50;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}


-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *otherView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    otherView.backgroundColor = ColorAlphe(245, 245, 245, 1);
    
    UILabel *sectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH-30, 50)];
    sectionLabel.text = [NSString stringWithFormat:@"%@",_sectionArr[section]];
    sectionLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:20];
    [otherView addSubview:sectionLabel];
    
    return section == 0 ? _setImgV : otherView;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return nil;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section != 4)
    {
        NSString *cellid = @"cellid";
        
//        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        
        if(!cell)
        {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
        }
        
        
        UITextField *textField = [UITextField new];
        textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [cell.contentView addSubview:textField];
        textField.font = Font(16);
        textField.tag = indexPath.section;
        
        // 富文本
        NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@",_cellArr[indexPath.section]] attributes:
                                          @{NSForegroundColorAttributeName:GrayColor,
                                            NSFontAttributeName:textField.font
                                            }];
        textField.attributedPlaceholder = attrString;
        
        textField.text = _textCellArr[indexPath.section];
        
        textField.sd_layout.leftSpaceToView(cell.contentView, 15).topSpaceToView(cell.contentView, 0).rightSpaceToView(cell.contentView, 15).bottomSpaceToView(cell.contentView, 0);
        
        return cell;
    }
    else
    {
        cell4 = [tableView dequeueReusableCellWithIdentifier:@"seller4"];
        if(!cell4)
        {
            cell4 = [[SetSlideCellTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"seller4"];
        }
        cell4.delegate = self;
        
        [cell4 requestMinVale:_minAgeInput maxValue:_maxAgeInput];
        
        cell4.minLabel.text = [NSString stringWithFormat:@"Min: %@",_minAgeInput]; //@"Min: 18";
        cell4.maxLabel.text = [NSString stringWithFormat:@"Max: %@",_maxAgeInput]; //@"Max: 36";
        
        return cell4;
    }
    
}

-(void)clickImgButtonTag:(NSInteger)tag
{
    imgBtnTag = tag;

    NSUInteger sourceType = 0;
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
    {
        sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    //初始化UIImagePickerController类
    UIImagePickerController *pc = [[UIImagePickerController alloc] init];
    pc.view.backgroundColor = [UIColor whiteColor];
    pc.allowsEditing = YES;
    pc.delegate = self;
    pc.navigationBarHidden = YES;
    pc.sourceType = sourceType;  //判断数据来源为相簿
    [self presentViewController:pc animated:YES completion:nil];
}

#pragma mark - UIImagePickerController
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    [picker dismissViewControllerAnimated:YES completion:nil];
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    
    if(!image)
    {
        
    }
    else
    {
        switch (imgBtnTag)
        {
            case 100:
                [_imgCurrentArr replaceObjectAtIndex:0 withObject:image];
                break;
            case 101:
                [_imgCurrentArr replaceObjectAtIndex:1 withObject:image];
                break;
            case 102:
                [_imgCurrentArr replaceObjectAtIndex:2 withObject:image];
                break;
                
            default:
                break;
        }
        
        [self loadImgThree:imgBtnTag];
    }
}


#pragma mark - 取消返回
-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}


-(void)clickSlideValueTag:(NSInteger)tag withValue:(NSString *)value
{
    switch (tag)
    {
        case 100:
            _minAgeInput = value;
            cell4.minLabel.text = [NSString stringWithFormat:@"Min: %@",_minAgeInput];
            break;
        case 101:
            _maxAgeInput = value;
            cell4.maxLabel.text = [NSString stringWithFormat:@"Max: %@",_maxAgeInput];
            break;
            
        default:
            break;
    }
}

- (void)mobileText:(NSNotification *)obj
{
    UITextField * tf = obj.object;
    
    if (tf.tag == 0)
    {
        _nameInput = tf.text;
    }
    else if (tf.tag == 1)
    {
        _jobInput = tf.text;
    }
    else if (tf.tag == 2)
    {
        _ageInput = tf.text;
    }
    else if (tf.tag == 3)
    {
        _bioInput = tf.text;
    }
    
    if(_nameInput.length == 0 || _jobInput.length == 0 || _ageInput.length == 0 || _bioInput.length == 0)
    {
        _isData = 0;
    }
    else
    {
        _isData = 1;
    }
    
    [_textCellArr replaceObjectAtIndex:0 withObject:_nameInput];
    [_textCellArr replaceObjectAtIndex:1 withObject:_jobInput];
    [_textCellArr replaceObjectAtIndex:2 withObject:_ageInput];
    [_textCellArr replaceObjectAtIndex:3 withObject:_bioInput];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    [self.view endEditing:YES];
    
    if (_table.contentOffset.y <= 0)
    {
        _table.bounces = NO;
        //NSLog(@"禁止下拉");
    }
    else
    {
        if (_table.contentOffset.y >= 0)
        {
            _table.bounces = YES;
            //NSLog(@"允许上拉");
        }
    }
        
    if(scrollView.contentOffset.y >= 60)
    {
        self.setTopV.settingTitle.hidden = NO;
        self.setTopV.topView.backgroundColor = ColorAlphe(221, 221, 221, 1);
    }
    else
    {
        self.setTopV.settingTitle.hidden = YES;
        self.setTopV.topView.backgroundColor = WhiteColor;
    }
    
}

#pragma mark -- SetTopBtnDelegate
-(void)clickButtonTag:(NSInteger)tag
{
    switch (tag) {
        case 100:
            [self dismissViewControllerAnimated:YES completion:nil];
            break;
            
        case 101:
            NSLog(@"退出登陆");
            [self creatLogin];
            break;
            
        case 102:
            NSLog(@"保存");
            
            if([_minAgeInput integerValue] > [_maxAgeInput integerValue])
            {
                //NSLog(@"年龄范围不对");
                [SVProgressHUD showErrorWithStatus:@"最小年龄不能大于最大年龄"];
                [SVProgressHUD dismissWithDelay:SVPROGRESSHUDTIME];
            }
            else
            {
                if(_isData)
                {
                    // 检索是否有空的图片存在，过滤掉空数组
                    NSMutableArray *arrList = [[NSMutableArray alloc]init];
                    
                    for (int i = 0; i < _imgCurrentArr.count; i ++)
                    {
                        if([_imgCurrentArr[i] isKindOfClass:[UIImage class]])
                        {
                            [arrList addObject:_imgCurrentArr[i]];
                        }
                        else
                        {
                            NSLog(@"当前下标对应的不是image类型，在此判断是否URL图片");
                            
                            if([_imgCurrentArr[i] rangeOfString:@"http"].location != NSNotFound)
                            {
                                // 是路径就不需要在上传一次专门获取路径，直接加入数组即可
                                [arrList addObject:_imgCurrentArr[i]];
                            }
                        }
                    }
                    
                    // 保存时先把存在的图片上传服务器拿到返回图片的路径  之后在执行保存接口上传所有数据
                    [self.arrSaveImg removeAllObjects];
                    
                    for (int i = 0; i < arrList.count; i ++)
                    {
                        if([arrList[i] isKindOfClass:[UIImage class]])
                        {
                            kWeakSelf(self);
                            [HttpDatas requestImgUploadFile:arrList[i] success:^(id  _Nonnull json) {
                                
                                if([json isKindOfClass:[NSDictionary class]])
                                {
                                    if([json[@"status"]integerValue] == 200)
                                    {
                                        [weakself.arrSaveImg addObject:json[@"data"]];
                                        
                                        NSLog(@"save %@",self.arrSaveImg);
                                        
                                        if(i == arrList.count-1)
                                        {
                                            weakself.numSave = 1;
                                            [weakself saveReauestDara];
                                        }
                                    }
                                }
                                
                            } failure:^(NSError * _Nonnull err) {
                                
                                [SVProgressHUD showErrorWithStatus:@"保存失败"];
                                [SVProgressHUD dismissWithDelay:SVPROGRESSHUDTIME];
                                
                            }];
                        }
                        else
                        {
                            if([arrList[i] rangeOfString:@"http"].location != NSNotFound)
                            {
                                // 是路径就不需要在上传一次专门获取路径，直接加入数组即可
                                [self.arrSaveImg addObject:arrList[i]];
                            }
                            else
                            {
                                [SVProgressHUD showErrorWithStatus:@"保存失败"];
                                [SVProgressHUD dismissWithDelay:SVPROGRESSHUDTIME];
                            }
                        }
                    }
                    
                    [self saveReauestDara];
                }
                else
                {
                    [SVProgressHUD showErrorWithStatus:@"个人信息填写不完整"];
                    [SVProgressHUD dismissWithDelay:SVPROGRESSHUDTIME];
                }
            }
            break;
            
        default:
            break;
    }
    
}

-(void)saveReauestDara
{
    NSString *firstImg,*twoImg,*threeImg;
    
    firstImg =   @"";
    twoImg =     @"";
    threeImg =   @"";
    
    switch (self.arrSaveImg.count)
    {
        case 1:
            firstImg = self.arrSaveImg[0];
            break;
            
        case 2:
            firstImg = self.arrSaveImg[0];
            twoImg = self.arrSaveImg[1];
            break;
            
        case 3:
            firstImg = self.arrSaveImg[0];
            twoImg = self.arrSaveImg[1];
            threeImg = self.arrSaveImg[2];
            break;
            
        default:
            break;
    }
    
    
    kWeakSelf(self);
    [HttpDatas requestSaveOneSelfDataToken:@"f2e0c88f-7d32-3464-9cc5" photo:self.curArrSave[0] photo1:firstImg photo2:twoImg photo3:threeImg user_name:_textCellArr[0] age:_textCellArr[2] work:_textCellArr[1] bio:_textCellArr[3] age_min:_minAgeInput age_max:_maxAgeInput success:^(id  _Nonnull json) {
        
        if([json isKindOfClass:[NSDictionary class]])
        {
            if([json[@"status"] integerValue] == 200)
            {
                if(weakself.numSave == 0)
                {
                    [SVProgressHUD showSuccessWithStatus:json[@"message"]];
                    [SVProgressHUD dismissWithDelay:SVPROGRESSHUDTIME];
                }
            }
        }
        
    } failure:^(NSError * _Nonnull err) {
        if(weakself.numSave == 0)
        {
            [SVProgressHUD showSuccessWithStatus:@"保存失败，请退出稍后再试"];
            [SVProgressHUD dismissWithDelay:SVPROGRESSHUDTIME];
        }
    }];
    
    _numSave = 0;
    
}



// 退出登陆
-(void)creatLogin
{
    [YXUserdefaults PutDefaults:@"isLogin" Value:@"NO"];
    [YXUserdefaults PutDefaults:@"email" Value:@""];
    [YXUserdefaults PutDefaults:@"password" Value:@""];
    [YXUserdefaults PutDefaults:@"token" Value:@""];
    
    UINavigationController *navRegist = [[UINavigationController alloc]initWithRootViewController:[NSClassFromString(@"LoginViewController") new]];
    
    [self presentViewController:navRegist animated:YES completion:nil];
}

//键盘弹出后将视图向上移动
-(void)keyboardWillShow:(NSNotification *)note
{
    NSDictionary *info = [note userInfo];
    CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
    
    //目标视图UITextField
    CGRect frame = self.view.frame;
    int y = frame.origin.y + frame.size.height - (self.view.frame.size.height - keyboardSize.height);
    NSTimeInterval animationDuration = 0.30f;
    [UIView beginAnimations:@"ResizeView" context:nil];
    [UIView setAnimationDuration:animationDuration];
    if(y > 0)
    {
        self.view.frame = CGRectMake(0, -y, self.view.frame.size.width, self.view.frame.size.height);
    }
    [UIView commitAnimations];
}

//键盘隐藏后将视图恢复到原始状态
-(void)keyboardWillHide:(NSNotification *)note
{
    NSTimeInterval animationDuration = 0.30f;
    [UIView beginAnimations:@"ResizeView" context:nil];
    [UIView setAnimationDuration:animationDuration];
    self.view.frame =CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    [UIView commitAnimations];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
